#include "BuildScreen.h"
#include "BaseGame.h"
#include "AudioManager.h"
int IglooCost = 950;
int IglooSize = 10;
int PolarbearGrinderCost = 2000;
int PolarBearGrinderSize = 14;
int CandyCaneCost = 350;
int CandyCaneSize = 3;
int RaindeerCost = 2500;
int RaindeerSize = 17;

BuildScreen::BuildScreen(hgeFont* font,GameData* gameData) :BaseScreen(font, gameData)
{
	totalBuildingAcres = 0;
	timer0 = 0;
	timerStart = false;
	HTEXTURE tex = g_pHge->Texture_Load("Content/igloo01b.png");
	HTEXTURE tex2 = g_pHge->Texture_Load("Content/cane01.png");
	HTEXTURE tex3 = g_pHge->Texture_Load("Content/raindeer01.png");
	HTEXTURE tex4 = g_pHge->Texture_Load("Content/polarbearGrinder.png");
	HTEXTURE tex5 = g_pHge->Texture_Load("Content/build.png");
	buildings[0] =		new hgeGUIButton(1, 175, 35, 64, 64, tex, 0, 0);
	buildings[1] =		new hgeGUIButton(2, 490, 35, 64, 64, tex2, 0, 0);
	buildings[2] =		new hgeGUIButton(3, 175, 135, 64, 64, tex3, 0, 0);
	buildings[3] =		new hgeGUIButton(4, 490, 135, 64, 64, tex4, 0, 0);

	hGui = new hgeGUI();
	hGui->Enter();
	hGui->AddCtrl(buildings[0]);
	hGui->AddCtrl(buildings[1]);
	hGui->AddCtrl(buildings[2]);
	hGui->AddCtrl(buildings[3]);
	message = "";

	m_backgroundSprite = new hgeSprite(tex5, 0,0,g_pHge->Texture_GetWidth(tex5), g_pHge->Texture_GetHeight(tex5));
	HTEXTURE tex6 = g_pHge->Texture_Load("Content/particles.png");
	
	hgeSprite* parSprite = new hgeSprite(tex6,0,0,32, 32);
	m_particle = new hgeParticleSystem("Content/particle1.psi", parSprite);

	 m_particleTimer = 0.0f;
	 m_particleTrigger = 3.0f;
}


BuildScreen::~BuildScreen(void)
{
}

void BuildScreen::Update(float fDeltaTime)
{
	guiId = hGui->Update(fDeltaTime);

	if(guiId != 0)
	{
		switch (guiId)
		{
		case 1:
			if(pGameData->ControlledAcres - totalBuildingAcres >= IglooSize && pGameData->Gold > (IglooCost * pGameData->Bartering))
			{
				pGameData->Igloos++;
				pGameData->Gold -= (IglooCost * pGameData->Bartering);
				pGameData->HelpersAvailable += pGameData->InhabitansPerIgloo;
				totalBuildingAcres += IglooSize;
				g_pAudioManager->PlayEffect("workshop");
			}
			else
			{
				message = "You need atleast 10 free acres \nand %.0f gold to build this structure";
				messageValue = IglooCost * pGameData->Bartering;
				timerStart = true;
			}
			break;
		case 2:
			if(pGameData->ControlledAcres - totalBuildingAcres >= CandyCaneSize && pGameData->Gold > (CandyCaneCost * pGameData->Bartering))
			{
				pGameData->CandyCaneFactories++;
				pGameData->Gold -= (CandyCaneCost * pGameData->Bartering);
				totalBuildingAcres += CandyCaneSize;
				g_pAudioManager->PlayEffect("workshop");

			}
			else
			{
				message = "You need atleast 3 free acres \nand %.0f gold to build this structure";
				messageValue = CandyCaneCost * pGameData->Bartering;
				timerStart = true;
			}
			break;
		case 3:
			if(pGameData->ControlledAcres - totalBuildingAcres >= RaindeerSize && pGameData->Gold > (RaindeerCost * pGameData->Bartering))
			{
				pGameData->RaindeerFarms++;
				pGameData->Gold -= (RaindeerCost * pGameData->Bartering);
				totalBuildingAcres += RaindeerSize;
				g_pAudioManager->PlayEffect("workshop");

			}
			else
			{
				message = "You need atleast 17 free acres \nand %.0f gold to build this structure";
				messageValue = RaindeerCost * pGameData->Bartering;
				timerStart = true;
			}
			break;
		case 4:
			if(pGameData->ControlledAcres - totalBuildingAcres >= PolarBearGrinderSize && pGameData->Gold > (PolarbearGrinderCost * pGameData->Bartering))
			{
				pGameData->PolarbearGrinders++;
				pGameData->Gold -= (PolarbearGrinderCost * pGameData->Bartering);
				pGameData->Bartering += 0.1f;
				pGameData->ExploringCoeff += 0.1f;
				pGameData->InhabitansPerIgloo += 1;
				pGameData->GoldCoef += 0.1f;
				totalBuildingAcres += PolarBearGrinderSize;
				g_pAudioManager->PlayEffect("workshop");

			}
			else
			{
				message = "You need atleast 14 free acres \nand %.0f gold to build this structure";
				messageValue = PolarbearGrinderCost * pGameData->Bartering;
				timerStart = true;
			}
			break;
		default:
			break;
		}
		
	}

	if(timerStart)
	{
		timer0 += fDeltaTime;

		if(timer0 > 3)
		{
			timer0 = 0;
			timerStart = false;
			message = "";
		}
	}
	m_particle->Update(fDeltaTime);

	m_particleTimer+= fDeltaTime;

	if(m_particleTimer >= m_particleTrigger )
	{
		m_particleTimer -= m_particleTrigger;
		m_particle->FireAt(650,280);
		g_pAudioManager->PlayEffect("bubble");
	}

}


void BuildScreen::Render()
{
	pFont->SetColor( ARGB(255,0,0,0));
	m_backgroundSprite->Render(143,0);
	m_particle->Render();
	hGui->Render();

	pFont->printf(300, 10,HGETEXT_LEFT,	"Build new structures");

	pFont->SetScale(0.5f);
	if(message != "")
	{
		
		pFont->printf(450, 220, HGETEXT_LEFT, message, messageValue);

	}

	pFont->printf(450, 270,HGETEXT_LEFT,	"Gold: %.0f", pGameData->Gold);
	pFont->printf(450, 300,HGETEXT_LEFT,	"Free Acres: %.0f", pGameData->ControlledAcres - totalBuildingAcres);

	pFont->SetColor( ARGB(255,155,100,155));

	pFont->printf(160, 520,HGETEXT_LEFT,	"Igloos %i", pGameData->Igloos);
	pFont->printf(160, 540,HGETEXT_LEFT,	"Polarbear Grinders: %i", pGameData->PolarbearGrinders);
	pFont->printf(360, 520,HGETEXT_LEFT,	"Candy Cane Factories: %i", pGameData->CandyCaneFactories);
	pFont->printf(360, 540,HGETEXT_LEFT,	"Rainder Farms: %i", pGameData->RaindeerFarms);


	pFont->SetScale(1.0f);

}
